package cn.iocoder.yudao.module.member.assets.api;

import cn.iocoder.yudao.module.api.member.assets.MemberDigitalAssetsApi;
import cn.iocoder.yudao.module.api.member.assets.dto.MemberDigitalAssetsRespDTO;
import cn.iocoder.yudao.module.api.member.assets.enums.CryptocurrencyDeductionType;
import cn.iocoder.yudao.module.member.assets.convert.MemberDigitalAssetsConvert;
import cn.iocoder.yudao.module.member.assets.dal.dataobject.MemberDigitalAssetsDO;
import cn.iocoder.yudao.module.member.assets.service.AppMemberDigitalAssetsService;
import cn.iocoder.yudao.module.member.assets.vo.AppMemberDigitalAssetsRespVO;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/02/07
 */
@Service
@Validated
public class MemberDigitalAssetsApiImpl implements MemberDigitalAssetsApi {

    @Resource
    private AppMemberDigitalAssetsService memberDigitalAssetsService;

    @Nonnull
    @Override
    public MemberDigitalAssetsRespDTO getDetail(Long userId) {
        if (userId == null || userId <= 0L) {
            return MemberDigitalAssetsRespDTO.EMPTY;
        }
        MemberDigitalAssetsDO digitalAssets = memberDigitalAssetsService.getOrCreate(userId);
        if (digitalAssets == null) {
            return MemberDigitalAssetsRespDTO.EMPTY;
        }
        return MemberDigitalAssetsConvert.INSTANCE.convert(digitalAssets);
    }

    @Override
    public Map<Long, MemberDigitalAssetsRespDTO> getMapByUserIds(Set<Long> userIds) {
        List<AppMemberDigitalAssetsRespVO> list = memberDigitalAssetsService.getListByUserIds(userIds);
        Map<Long, MemberDigitalAssetsRespDTO> digitalAssetsMap = new HashMap<>();
        for (AppMemberDigitalAssetsRespVO it : list) {
            digitalAssetsMap.put(it.getUserId(), MemberDigitalAssetsConvert.INSTANCE.convert(it));
        }
        return digitalAssetsMap;
    }

    @Override
    public void unfreezeCryptocurrencyOrigin(Long userId, Double number) {
        memberDigitalAssetsService.unfreezeCryptocurrencyOrigin(userId, number);
    }

    @Override
    public CryptocurrencyDeductionType payCryptocurrencyIncrement(Long userId, Double number) {
        return memberDigitalAssetsService.payCryptocurrencyIncrement(userId, number);
    }

    @Override
    public void refundCryptocurrencyIncrement(Long userId, Double number) {
        memberDigitalAssetsService.refundCryptocurrencyIncrement(userId, number);
    }

    @Override
    public void exchangeCryptocurrencyOriginToIncrement(Long userId, Double number) {
        memberDigitalAssetsService.exchangeCryptocurrencyOriginToIncrement(userId, number);
    }

    @Override
    public void changeCryptocurrencyOrigin(Long userId, Double number) {
        memberDigitalAssetsService.changeCryptocurrencyOrigin(userId, number);
    }

    @Override
    public void changeCryptocurrencyFreezing(Long userId, Double number) {
        memberDigitalAssetsService.changeCryptocurrencyFreezing(userId, number);
    }

    @Override
    public void exchangeCryptocurrencyOriginToIncreasing(Long userId, Double number) {
        memberDigitalAssetsService.exchangeCryptocurrencyOriginToIncreasing(userId, number);
    }

    @Override
    public void increaseCryptocurrencyIncrement(Long userId, Double number) {
        memberDigitalAssetsService.increaseCryptocurrencyIncrement(userId, number);
    }

    @Override
    public void returnCryptocurrencyIncreasing(Long userId, Double number) {
        memberDigitalAssetsService.returnCryptocurrencyIncreasing(userId, number);
    }

    @Override
    public void changeBonus(Long userId, Double number) {
        memberDigitalAssetsService.changeBonus(userId, number);
    }

}
